Dual Sensors for a Stamp part II

by Jim Ubersetzig

This article was published in the April 1999 issue of The Robot Builder.

This is a follow-up to the article "Dual Sensors for a STAMP".

Introduction

Have you ever wanted to add sensors to your robot - but weren't sure how to do it ?

In this two part article I will show you how to build a pair of inexpensive Sonar and Infra Red (IR) sensors which share a Basic Stamp 1 computer. By operating both sensors off the same stamp computer - you save cost.

Last month we built the Sonar sensor and demonstrated its ability to measure the distance to an object. This month we will build an infra red (IR) sensor which reports the probability of objects to the right, to the left and directly ahead of the robot. The IR sensor reports confidence numbers, which are probabilities in the range 1 through 10. If the right confidence number is 10, the path is clear to the right. A high left number indicate confidence that the robot could turn left without striking an obstacle. When both left and right report 10, the robot can safely roll forward.

Parts and Cost

You have the choice of building the IR sensor assembly from parts you purchase or building it from a kit. The design of the IR sensor assembly is from "Standard Technologies of the Seattle Robotics Society" and can be found at:

www.seattlerobotics.org/guide/infrared.html

available as a kit from Lynxmotion. The kit has the advantage of a printed circuit board - which simplifies assembly. In addition to the Basic Stamp 1, and 9 volt battery you purchased for part one of this article, you will need either:

IRPD-01 kit (approximately $35) from Lynxmotion www.lynxmotion.com (309)382-1816

or else purchase this list of parts and build it yourself. Costs given are approximate:

To load the software in this article into the Basic Stamp, you need a PC. The stamp also uses the PC to display test results. If you use the remaining Basic Stamp pins to build a robot base to mount the sensor on, then the robot could operate without the PC.

Skills Required

You will need certain minimum skills to complete the device described in this article:

- Soldering, electronic grade.
- Cutting plastic sheet.
- Drilling holes.
- Safety skills to avoid injuries.

Construction - Kit

If you build the IR board from the kit, the manual is excellent.  You might be able to set the trim pot without measuring the frequency - the correct setting for the author's kit was 1:45pm (noon being half way).

Construction - Do It Yourself

Begin by cutting a piece of perfboard at least 1-1/2" by 2-1/4". Mount the Sharp receiver module at the center of a long side of the board. Solder a short wire from the ground pin to the metal case. Now mount the IR LEDs on both sides of the receiver module. Leave the leads long and bend them at 90 degrees so the IR LEDs and the receiver module point in the same direction.

Next angle the LEDs out at about 30 degrees to the left and right. (see figure 3 ) The rest of the parts can be mounted anywhere on the perfboard. Wire the transmitter section as shown below:

Now wire the receiver as shown. Mount the 0.1 uF capacitor close to the receiver module. Bend the capacitor leads and solder directly to the ground and +5V pins of the receiver module.
 

 

Theory of Operation

The IR sensor operates by bouncing infra red (non visible light) off objects.  Two IR transmitters produce brief bursts of light, while a IR receiver looks for reflections from nearby objects. The electronics works like this:

Two sections of the 74HC04 are used to form an oscillator. The 10K ohm trimpot is for adjusting the operating frequency to 40KHz. The alternating voltage from the oscillator is applied to both IR LED's. A voltage is applied to the other side of each LED to select which LED emits light.

The IR receiver module was designed for IR remote controls, so the oscillator must be tuned to match the required 40KHz light flash rate. IR is radiant heat, and most objects don't change temperature 40,000 times per second, so hot objects do not affect the IR receiver. However sunlight contains LOTS of IR, and will  stop the IR sensor from working.

The optical components are mounted with overlapping fields of view to distinguish between objects to the right, to the left and straight ahead.

In this diagram, you are looking down at the robot. The software leaves the left IR LED off, and flashes the right LED ten times, counting the number of of received flashes. Then the process is repeated with the right LED off, flashing the left LED ten times. Confidence numbers are reported for right and for left.

The secret of getting a reliable reading for directly ahead of the robot is careful alignment of the IR LEDs. Then when both right and left confidence numbers report 10, the robot is clear to roll forward.

There are a couple of things to keep in mind when using the confidence numbers:
1. Sunlight from a window will prevent operation of the sensor.
2. When both numbers are large (9 or 10), the robo can roll forward.
3. With right number large and left number small, the robot should turn right.
4. Left larger than right means turn left.
5. If both numbers are small ( 1 to 2). the robot should  back up.

The Cable

You need to build a cable to connect the Basic Stamp 1 to the IR board. Build it to match the wiring diagram:

Software
Here is the Basic Stamp code used in this project:
'
' Test software for the Infra Red sensor
' derived from the IRPD manual.
' 31 May 98
' Runs on the Basic Stamp BS1-IC
'
' BS1-IC    IRPD   function
' Pin       Pin
' P2        5      IR sensor input
' P3        4      Look Right
' P4        3      Look Left
' Vdd       6      +5VDC
' Vss       8      ground
' symbols
symbol temp = b2
symbol x = w2
dirs = %00011001     ' P0,P3,P4 = are outputs, others are inputs
start: temp = 0
  for x=1 to 10         ' do this ten times
    pin3 = 1         ' shine IR light to the right
    pin3 = 0                ' turn it off
    temp = temp + pin2      ' count the misses
  next x
  debug "right ",#temp,cr   ' display 0-3 for obstacle,
                            ' 7-10 for nothing.
  for x=1 to 750 :next      ' delay for reading display.
  temp = 0
  for x=1 to 10             ' do this ten times
      pin4 = 1              ' shine IR light to the left
      pin4 = 0              ' turn it off
      temp = temp + pin2    ' count the misses
  next x
  debug "left ",#temp,cr    ' display 0-3 for obstacle,
                            ' 7-10 for nothing.
  for x=1 to 750 :next      ' delay for reading display.
  goto start
' End of the software

Get It Working ?

On your PC type stamp <enter> and the stamp development system will come up. If you don't have this file ( stamp.exe  approx 15K bytes ), it's a free
download from the parallax web site at www.parallaxinc.com. It also comes with the developer's kit, along with the cable. If you don't have the cable, instructions for building one are on the web site.

On your PC you should see a blue screen. Type in the software, then ALT-S to save the software in a file. Type in a suitable file name, then <enter>. Now ALT-Q to exit.  The software is saved on your PC.

To operate the IR sensor:
On the PC type stamp <enter>
You'll see the blue screen again. ALT-L will let you select the software you have previously saved.

Once you see the software on the PC display, hook up the cable from your PC's com port to the stamp. NOTE that the cable can go two different
ways on the stamp. Line up the marks !

Now ALT-R will start the software running. You should see a list of numbers on the computer screen.

These are the confidence numbers reported by the IR sensor. Place an object where the sensor should see it and the numbers should change.  Experiment with different objects and different distances.

Troubleshooting

If things don't work as expected, there are adjustments:

First, check the software you typed in. Did you copy it exactly ?

If all the numbers are zero - the receiver is viewing the transmitting IR LEDS.  Bend the leads of the LEDS so the lens of the LED is behind the front
face of the receiver module. Or place cardboard between the transmitters and the receiver. If the numbers reported vary widely (or are always 10), the oscillator requires adjustment. This can be measured with a frequency counter, some digital voltmeters have this built in. Alternately you can measure the period with a scope. The period for 40KHz is about 25 microseconds. If the sensor is too sensitive ( detects objects too far away ), place layers of clear adhesive tape over the opening in the sharp IR receiver module. The author found that six layers of scotch tape were best.

The Future ?

Many improvements are possible, and the author encourages experimentation. Try things. Some of your ideas will work.